home *** CD-ROM | disk | FTP | other *** search
Wrap
/* this modual contains all the routines to handle the scrolling of a window. This routine is called from the "do mouse" modual. */ #include "my color.h" pascal void up_action(ControlHandle, short); pascal void down_action(ControlHandle, short); pascal void page_up_action(ControlHandle, short); pascal void page_down_action(ControlHandle, short); pascal void thumb_action(void); Boolean do_controls(the_window, where) /* the_window is, obviously, the window that is active, "where" is the point where the mouse was clicked, in global cooridiates, inside the active window. do_controls() will return TRUE is a control was clicked in otherwise it will return FALSE */ CWindowPtr the_window; Point where; { short part_code, new_value, which_control, old_value; short scroll_amount; ControlHandle the_control; CWindowPeek owner_window; GlobalToLocal(&where); /* first convert the mouse location to local coordinates */ part_code = FindControl(where, the_window, &the_control); /* now find out what part of the window was clicked in */ if(!part_code) return FALSE; /* if part_code is NULL, then the scroll bars were not clicked in */ switch(part_code) { case inUpButton: /* the user clicked in the UP arrow of the scroll bar */ TrackControl(the_control, where, up_action); break; case inDownButton: /* the user clicked in the DOWN arrow of the scroll bar */ TrackControl(the_control, where, down_action); break; case inPageUp: /* the user is clicking in the page up region of the scroll bar */ TrackControl(the_control, where, page_up_action); break; case inPageDown: /* the user is clicking in the page down region of the scroll bar */ TrackControl(the_control, where, page_down_action); break; case inThumb: /* the user is draging the "thumb" around */ old_value = GetCtlValue(the_control); /* this is the last value the control had before the current activity */ TrackControl(the_control, where, thumb_action); new_value = GetCtlValue(the_control); /* this is the last value the control had before the current activity */ owner_window = (CWindowPeek)(**the_control).contrlOwner; /* I refere to the control's owning window so that I can easily get to the text edit record */ scroll_amount = old_value - new_value; which_control = GetCRefCon(the_control); /* this is the control that was clicked in */ if(which_control == VERTICLE_SCROLL) /* if we're in the verticle scroll bar move the text down */ TEScroll(0, scroll_amount, (TEHandle)owner_window->refCon); else if (which_control == HORIZONTAL_SCROLL) /* if we're in the horizontal scroll bar move the text to the left */ TEScroll(scroll_amount, 0, (TEHandle)owner_window->refCon); break; default: /* default to a SysBeep 'cause that will mean something is wrong */ SysBeep(11); break; } return TRUE; } pascal void up_action(control, part) /* TrackControl will repeatedly call this routine as long as the mouse is held down in the UP arrow of the scroll bar */ ControlHandle control; short part; { short old_control_value, scroll_units, control_min_value, new_control_value; CWindowPeek owner_window; short which_control; scroll_units = 1; /* this is how many pixels I'll scroll the window */ which_control = GetCRefCon(control); /* this is the control that was clicked in */ old_control_value = GetCtlValue(control); /* this is the last value the control had before the current activity */ control_min_value = GetCtlMin(control); /* this is the minimum valu the control can have, this was defined when the control was created */ new_control_value = old_control_value - scroll_units; /* this is the new value that the control will have after the scrolling */ if(new_control_value < control_min_value) /* if the new control value isn't legitimate */ SetCtlValue(control, control_min_value);/* just set the control to the minimum value */ else /* else, set the control value to the new value, the scroll the text */ { SetCtlValue(control, new_control_value); owner_window = (CWindowPeek)(**control).contrlOwner; /* I refere to the control's owning window so that I can easily get to the text edit record */ if(which_control == VERTICLE_SCROLL) /* if we're in the verticle scroll bar move the text down */ TEScroll(0, scroll_units, (TEHandle)owner_window->refCon); else if (which_control == HORIZONTAL_SCROLL) /* if we're in the horizontal scroll bar move the text to the left */ TEScroll(scroll_units, 0, (TEHandle)owner_window->refCon); } } pascal void down_action(control, part)/* TrackControl will call this routine repeatedly as long as the mouse is held down in the DOWN arrow */ ControlHandle control; short part; { short old_control_value, scroll_units, control_max_value, new_control_value; CWindowPeek owner_window; short which_control; scroll_units = 1; /* this is the number of pixels I'll scroll each time the routine is called */ which_control = GetCRefCon(control); /* this is the control the mouse was pressed in */ old_control_value = GetCtlValue(control); /* this is the value the controll had when it was last used */ control_max_value = GetCtlMax(control); /* this is the maximum value the control can obtain, this was set when the control was defined */ new_control_value = old_control_value + scroll_units; /* this is the value the control will be set to when we are done */ if(new_control_value > control_max_value) /* if the new control value too large then just set the control to the maximum value */ SetCtlValue(control, control_max_value); else /* else set the controll to the new value and scroll the test */ { SetCtlValue(control, new_control_value); owner_window = (CWindowPeek)(**control).contrlOwner; /* I refere to the control's owning window so that I can easily get to the text edit record */ if(which_control == VERTICLE_SCROLL) /* if we are in the verticle scroll bar then scroll up */ TEScroll(0, -scroll_units, (TEHandle)owner_window->refCon); else if (which_control == HORIZONTAL_SCROLL) /* else if we're in the horizontal scroll bar, scroll to the left */ TEScroll( -scroll_units, 0, (TEHandle)owner_window->refCon); } } pascal void page_up_action(control, part) /* TrackControl will repeatedly call this routine as long as the mouse is held down in the PageUp region of the scroll bar */ ControlHandle control; short part; { short old_control_value, scroll_units, control_min_value, new_control_value; CWindowPeek owner_window; short which_control; scroll_units = 45; /* this is the number of pixels I'll scroll each time this routine is called */ which_control = GetCRefCon(control); old_control_value = GetCtlValue(control); /* this is the value of the scroll bar from the last time it was used */ control_min_value = GetCtlMin(control); /* this is the minimum value the scroll bar can obtain, this was set when the scroll bar was defined */ new_control_value = old_control_value - scroll_units; /* this is the new value for the control */ if(new_control_value < control_min_value) scroll_units = old_control_value - control_min_value; if(old_control_value <= control_min_value) /* if the new value is too small, just set the control to the minimum value */ SetCtlValue(control, control_min_value); else /* if everything is O.K., set the control to the new value, and scroll the window */ { SetCtlValue(control, old_control_value - scroll_units); owner_window = (CWindowPeek)(**control).contrlOwner; /* I refer to the control's owning window so that I can easily get to the text edit record */ if(which_control == VERTICLE_SCROLL) /* if we're in the verticle scroll bar page area, then page down */ TEScroll(0, scroll_units, (TEHandle)owner_window->refCon); else if (which_control == HORIZONTAL_SCROLL) /* else if we are in the horizontal scroll bar, page right */ TEScroll(scroll_units, 0, (TEHandle)owner_window->refCon); } } pascal void page_down_action(control, part) /* TrackControl will repeatedly call this routine as long as the mouse is held down in the PageDown region of the scroll bar */ ControlHandle control; short part; { short old_control_value, scroll_units, control_max_value, new_control_value; CWindowPeek owner_window; short which_control; scroll_units = 45; /* this is the amount I'll scroll each time this routine is acalled */ which_control = GetCRefCon(control); /* this is the ID of scroll bar that was choosen */ old_control_value = GetCtlValue(control);/* this is the value of the scroll bar from the last time it was used */ control_max_value = GetCtlMax(control); /* this is the maximum value the scroll bar can obtain */ new_control_value = old_control_value + scroll_units; /* this is the new value for the scroll bar */ if(new_control_value > control_max_value) scroll_units = control_max_value - old_control_value; if(old_control_value >= control_max_value) /* if the new value is too large, then just set the control to the maximum value and leave */ SetCtlValue(control, control_max_value); else /* else set the control to the new value, and the scroll the window */ { SetCtlValue(control, new_control_value); owner_window = (CWindowPeek)(**control).contrlOwner; /* I refere to the control's owning window so that I can easily get to the text edit record */ if(which_control == VERTICLE_SCROLL) /* if we are in the verticle scroll bar, then scroll up */ TEScroll(0, -scroll_units, (TEHandle)owner_window->refCon); else if (which_control == HORIZONTAL_SCROLL) /* if we are in the horizontal scroll bar then scroll to the left */ TEScroll(-scroll_units, 0, (TEHandle)owner_window->refCon); } } pascal void thumb_action() /* I just put this here as an example, I don't have anything to do while the user is draging the "thumb" around */ { return; }